package org.compiere.model;

import java.io.Reader;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

public class Mhrmtripnormativeline extends X_hrm_tripnormative_line {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8142164801883419042L;
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mhrmtripnormativeline.class);

	public Mhrmtripnormativeline(Properties ctx, int hrm_tripnormative_line_ID,
			String trxName) {
		super(ctx, hrm_tripnormative_line_ID, trxName);
		// TODO Auto-generated constructor stub
	}

	public Mhrmtripnormativeline(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * Select COST
	 * @param AD_CLIENT_ID
	 * @param C_COUNTRY_ID
	 * @param HRM_TRIPNORMATIVETYPE
	 * @return COST
	 */
	public static Mhrmtripnormativeline getCost(int C_Country_ID, String hrm_tripnormativetype) {
		//
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		Mhrmtripnormativeline hrmtrip = new Mhrmtripnormativeline(Env.getCtx(),0,null);
			
		// 
		String sql_ = "SELECT * FROM HRM_TRIPNORMATIVE_LINE \n " +
						"WHERE ISACTIVE='Y' \n " + 
						"AND AD_CLIENT_ID=" + Env.getAD_Client_ID(Env.getCtx()) + " \n " +
						"AND C_COUNTRY_ID=" + C_Country_ID + " \n " +
						"AND HRM_TRIPNORMATIVETYPE=" + hrm_tripnormativetype;
			try
			{
				pstmt = DB.prepareStatement(sql_,null);				
				rs = pstmt.executeQuery();	
				if(rs.next())
					hrmtrip = new Mhrmtripnormativeline(Env.getCtx(), rs, null);
			}
			catch (SQLException e)
			{
				s_log.log(Level.SEVERE, "product", e);
			}
			finally
			{
				DB.close(rs, pstmt);
				rs = null; pstmt = null;
			}	
		return hrmtrip;
		
	}
	
	/**
	 * Select COST
	 * @param AD_CLIENT_ID
	 * @param C_CITY_ID
	 * @param HRM_TRIPNORMATIVETYPE
	 * @return COST
	 */
	public static Mhrmtripnormativeline getCityCost(int C_City_ID, String hrm_tripnormativetype) {
		//
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		Mhrmtripnormativeline hrmtrip = new Mhrmtripnormativeline(Env.getCtx(),0,null);
			
		// 
		String sql_ = "SELECT * FROM HRM_TRIPNORMATIVE_LINE \n " +
						"WHERE ISACTIVE='Y' \n " +
						"AND AD_CLIENT_ID=" + Env.getAD_Client_ID(Env.getCtx()) + " \n " +
						"AND C_CITY_ID=" + C_City_ID + " \n " +
						"AND HRM_TRIPNORMATIVETYPE=" + hrm_tripnormativetype;
			try
			{
				pstmt = DB.prepareStatement(sql_,null);				
				rs = pstmt.executeQuery();	
				if(rs.next())
					hrmtrip = new Mhrmtripnormativeline(Env.getCtx(), rs, null);
			}
			catch (SQLException e)
			{
				s_log.log(Level.SEVERE, "product", e);
			}
			finally
			{
				DB.close(rs, pstmt);
				rs = null; pstmt = null;
			}	
		return hrmtrip;
		
	}
}
